package com.mobjam.workingtitleforagame.UnitTests;

import com.mobjam.workingtitleforagame.MainActivity;
import com.mobjam.workingtitleforagame.R;
import com.mobjam.workingtitleforagame.R.id;
import com.mobjam.workingtitleforagame.R.layout;

import android.app.Activity;
import android.app.Instrumentation;
import android.app.Instrumentation.ActivityMonitor;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;

public class MainActivityTest extends
		ActivityInstrumentationTestCase2<MainActivity> {
	private Instrumentation mainInstrumentation;
	private MainActivity mainActivity;
//	private Button button1;
//	private Button button2;
	private View mainLayout;

	public MainActivityTest() {
		super("com.mobjam.workingtitleforagame", MainActivity.class);
	}

	protected void setUp() throws Exception {
		super.setUp();
		mainInstrumentation = getInstrumentation();
		mainActivity = getActivity();
//		button1 = (Button) mainActivity.findViewById(R.id.button1);
//		button2 = (Button) mainActivity.findViewById(R.id.button2);
		mainLayout = (View) mainActivity.findViewById(R.layout.activity_main);
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

//	public void testOnCreateBundle() {
//		fail("Not yet implemented");
//	}
//
//	public void testOnCreateOptionsMenuMenu() {
//		fail("Not yet implemented");
//	}
//
//	public void testOnCreateDialogInt() {
//		fail("Not yet implemented");
//	}
	@UiThreadTest
	public void testMapActivityButton() {
//		ActivityMonitor activityMonitor = mainInstrumentation.addMonitor(MapActivity.class.getName(), null, false);
		final Button button1 = (Button) mainActivity.findViewById(R.id.button1);
		mainActivity.runOnUiThread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				button1.performClick();
			}
		});
		
//		sendKeys(KeyEvent.KEYCODE_DPAD_UP);
//		sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
//		sendKeys(KeyEvent.KEYCODE_BACK);
	}

	public void testDestroy() {
		mainActivity.finish();
		mainActivity = this.getActivity();
	}
	
	@UiThreadTest
	public void testHelpButton() {
		final Button button2 = (Button) mainActivity.findViewById(R.id.button2);
		mainActivity.runOnUiThread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				button2.performClick();
				
			}
			
		});
//		sendKeys(KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_CENTER);
//		sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
//		sendKeys(KeyEvent.KEYCODE_BACK);
	}

}
